package com.example.xx;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @description
 *
 * @author Barrettl
 * @date 2022/2/15 17:23
 **/
public class Practice6 {
    public static void main(String[] args) {
        int gap = 10;
        JFrame f = new JFrame("ToMysql");
        f.setSize(410, 600);
        f.setLocation(200, 200);
        f.setLayout(null);

        JPanel pInput = new JPanel();
        pInput.setBounds(gap, gap, 375, 120);
        pInput.setLayout(new GridLayout(4,3,gap,gap));




        JLabel content = new JLabel("content:");
        JTextField contentText = new JTextField();
        JLabel type = new JLabel("prefix:");
        JTextField typeText = new JTextField();
        JLabel ignore = new JLabel("ignore:");
        JTextField ignoreText = new JTextField();
        JRadioButton jr5=new JRadioButton("full");


        pInput.add(content);
        pInput.add(contentText);
        pInput.add(type);
        pInput.add(typeText);
        pInput.add(ignore);
        pInput.add(ignoreText);
        pInput.add(jr5);

        JButton b = new JButton("gen");
        b.setBounds(150, 120 + 30, 80, 30);

        //文本域
        JTextArea jta = new JTextArea(15,30);
        jta.setLineWrap(true);
        jta.setBounds(gap, 150 + 60, 375, 350);
        // jta.setAutoscrolls(true);

        JScrollPane jsp=new JScrollPane(jta);    //将文本域放入滚动窗口
        Dimension size=jta.getPreferredSize();    //获得文本域的首选大小
        jsp.setBounds(gap,150 + 60,size.width,size.height);

        f.add(pInput);
        f.add(b);
        f.add(jsp);
        // f.add(ta2);
        // f.add(contentText);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


        f.setVisible(true);
        //鼠标监听
        b.addActionListener(new ActionListener(){
            boolean checkedpass = true;
            public void actionPerformed(ActionEvent e){
                checkedpass = true;
                // checkEmpty(contentText,"content");
                // checkEmpty(typeText,"公司类型");


                if(checkedpass){
                    String result = ToSql02.process(contentText.getText(), typeText.getText(), ignoreText.getText(),jr5.isSelected());
                    jta.setText("");
                    jta.append(result);
                }

            }

            //检验是否为空
            private void checkEmpty(JTextField tf, String msg){
                if(!checkedpass)
                    return;
                String value = tf.getText();
                if(value.length()==0){
                    JOptionPane.showMessageDialog(f, msg + " 不能为空");
                    tf.grabFocus();
                    checkedpass = false;
                }
            }
            //检验输入金额必须是整数



        });

    }




}
